package com.wondersgroup.fjzlpt.org.controller.view.jgqy.qylb;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.boot.web.wapper.QuickPrincipal;
import com.wondersgroup.fjzlpt.org.dao.inter.jgqy.qysq.QysqDAO;
import com.wondersgroup.fjzlpt.org.dao.inter.yljgxx.YljgxxDAO;
import com.wondersgroup.fjzlpt.org.service.inter.jgqy.qysq.QysqService;

@Controller
@RequestMapping("qylb")
public class QylbController {
	
	@Autowired
	private YljgxxDAO yljgxxDAO;
	
	@Autowired
	private QysqDAO qysqDAO;
	
	@Autowired
	private QysqService qysqService;
	
	@RequestMapping("/index.html")
	public String index(HttpServletRequest request)
	{
        JSONObject json = new JSONObject();
        json.put("WSJGLBDM", QuickPrincipalUtils.getJglbdm(request));
        json.put("PTJGID", QuickPrincipalUtils.getPtjgID(request));
        request.setAttribute("userInfo", json);
		return "jgqy/qylb/index";
	}
	
	@RequestMapping("/jieshou.html")
	public String js(HttpServletRequest request)
	{
        Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			String yljgid = map.remove("YLJGID");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
			/**获取主导机构信息*/
			if(!StringUtils.isEmpty(yljgid)){
				map.put("YLJGID", yljgid);
			}else{
				map.put("YLJGID", jo.getString("ZDYLJGID"));
			}
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			request.setAttribute("fqyljgxx", json.get("rows"));
			request.setAttribute("GLID", map.get("GLID"));
		}
		return "jgqy/qylb/js";
	}
	
	@RequestMapping("/jy.html")
	public String jy(HttpServletRequest request)
	{
        Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			String yljgid = map.remove("YLJGID");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
			/**获取发起解约机构信息*/
			map.put("YLJGID", yljgid);
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			request.setAttribute("fqyljgxx", json.get("rows"));
			request.setAttribute("GLID", map.get("GLID"));
		}
		return "jgqy/qylb/jy";
	}
	
	@RequestMapping("/jysh.html")
	public String jysh(HttpServletRequest request)
	{
        Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			String yljgid = map.remove("YLJGID");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
			/**获取发起解约机构信息*/
			map.put("YLJGID", yljgid);
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			request.setAttribute("fqyljgxx", json.get("rows"));
			request.setAttribute("GLID", map.get("GLID"));
			request.setAttribute("JYYY", map.get("JYYY"));
		}
		return "jgqy/qylb/jysh";
	}
	
	@RequestMapping("/xy.html")
	public String xy(HttpServletRequest request)
	{
        Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
		}
		return "jgqy/qylb/xy";
	}
	
	
	@RequestMapping("/detail.html")
	public String detail(HttpServletRequest request)
	{
        Map<String, String> map = RequestUtils.GetParameterMap(request);
		if(map.containsKey("YLTID")){
			/**获取医联体信息*/
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject jo = qysqDAO.queryYltxx(map);
			jo = (JSONObject) (jo.getJSONArray("rows")).get(0);
			request.setAttribute("qysqxx", jo);
			/**获取签约机构信息*/
			map.put("YLTLX", jo.getString("YLTLX"));
			JSONArray ja = qysqService.queryQyJg(map);
			request.setAttribute("qyjgxx", ja);
			/**获取主导机构信息*/
			map.put("YLJGID", jo.getString("ZDYLJGID"));
			map.put("pageSize", "1");
			map.put("pageNumber", "1");
			JSONObject json = yljgxxDAO.queryPage(map);
			request.setAttribute("fqyljgxx", json.get("rows"));
		}
		return "jgqy/qylb/detail";
	}
	
	@RequestMapping("/lsDetail.html")
	public String lsDetail()
	{
		return "jgqy/qylb/lsDetail";
	}
	
}
